package scu.maqiang.homogenization;

import scu.maqiang.fes.BVPType;
import scu.maqiang.fes.FES2T3PE;
import scu.maqiang.mesh.MatrixFunc;
import scu.maqiang.mesh.Mesh2T3;
import scu.maqiang.mesh.MeshFormat;
import scu.maqiang.mesh.ScalarFunc;
import scu.maqiang.numeric.SRMatrix;

public class PEEigenValue2DT3SOTS {

	public static void main(String[] args) {
		double C11M = 8e9;
		double C12M = 4.4e9;
		double C1TM = 4.4e9;
		double C2TM = 4.4e9;
		double C22M = 8e9;
		double C12TM = 0.0;
		double CTTM = 8e9;
		double G12M = 1.8e9;

		double e111M = 0;
		double e122M = 0;
		double e1TM = 0;
		double e211M = -0.0;
		double e222M = -0.0;
		double e2TM = 0.0;
		double e112M = 0.0;
		double e212M = 0;

		double ep11M = 3.717e-11;
		double ep22M = 3.717e-11;
		double rho1 = 1100;

		double[][] MatEpoxy = { { C11M,   C12M,     0,  e111M,  e211M }, 
				                { C12M,   C22M,     0,  e122M,  e222M }, 
				                {     0,     0,  G12M,  e112M,  e212M }, 
				                { e111M, e122M, e112M, -ep11M,      0 }, 
				                { e211M, e222M, e212M,      0, -ep22M }}; 
	
		double C11N = 121e9;
		double C12N = 75.4e9;
		double C1TN = 75.4e9;
		double C2TN = 75.4e9;
		double C22N = 111e9;
		double C12TN = 0.0;
		double CTTN = 111e9;
		double G12N = 21.1e9;

		double e111N = 0;
		double e122N = 0;
		double e1TN = 0;
		double e211N = -5.4;
		double e222N = 15.8;
		double e2TN = -5.4; 
		double e112N = 12.3;
		double e212N = 0;

		double ep11N = 8.1368e-9;
		double ep22N = 7.3134e-9;
		double rho2 = 7800;
		
		double[][] MatPZT5A = {{  C11N,   C12N,       0,  e111N,  e211N},
				{  C12N,   C22N,       0,  e122N,  e222N},
				{     0,     0,     G12N,  e112N,  e212N},
				{ e111N,  e122N,   e112N, -ep11N,      0},
				{ e211N,  e222N,   e212N,     0,  -ep22N}};

		Mesh2T3 mesh2D = new Mesh2T3().readMesh("E:\\EclipseWorkspace2\\JFem\\MeshFile\\PEMacroTh.msh", MeshFormat.msh);
		mesh2D.toTecplot("PEMacroTh.dat");
		
		int RMM1 = 8;
		int RMM2 = 0;
		FES2T3PE fs = new FES2T3PE(mesh2D);
		SRMatrix Stiff = new SRMatrix(fs.GetNdof());
		SRMatrix Mass = new SRMatrix(fs.GetNdof());
		MatrixFunc matCoefFunc = (xy, label, param) -> label == RMM1? MatEpoxy : MatPZT5A;
		fs.assembleStiff(matCoefFunc, null, BVPType.CONSTITUTE_MATRIX_COMMON, Stiff);
		ScalarFunc massFunc = (xy, label, param) -> label == RMM1? rho1 : rho2;
		fs.assembleMass(new ScalarFunc[] {massFunc}, null, BVPType.CONSIST_MASS, Mass);
		Stiff.save("PEStiff.txt");
		Mass.save("PEmass.txt");
		
	}

}
